﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace myWindowsMediaPlayer
{
    /// <summary>
    /// Logique d'interaction pour MainWindow.xaml
    /// </summary>
    public partial class WindowsMediaView : Window
    {
        public WindowsMediaView()
        {
            InitializeComponent();
            DataContext = new MediaElementViewModel(media);
        }

        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MediaElementViewModel DataContextTmp = (MediaElementViewModel) DataContext;
            ListView action = (ListView)sender;
            PlaylistItem item = (PlaylistItem)action.SelectedItem;
            DataContextTmp.Source = item._path;
            DataContextTmp.mediaCmd.Execute("Pause");
        }
        /*
        private void Element_MediaOpened(object sender, EventArgs e)
        {
            MediaElementViewModel DataContextTmp = (MediaElementViewModel)DataContext;

            timelineSlider.Maximum = DataContextTmp.mediaView.NaturalDuration.TimeSpan.TotalMilliseconds;
        }

        private void Element_MediaEnded(object sender, EventArgs e)
        {
            MediaElementViewModel DataContextTmp = (MediaElementViewModel)DataContext;

            DataContextTmp.mediaCmd.Execute("Next");
            TimeSpan ts = new TimeSpan(0, 0, 0, 0, 0);
            timelineSlider.Value = 0; 
            DataContextTmp.mediaView.Position = ts;
        }

        private void SeekToMediaPosition(object sender, RoutedPropertyChangedEventArgs<double> args)
        {
            int SliderValue = (int)timelineSlider.Value;
            MediaElementViewModel DataContextTmp = (MediaElementViewModel)DataContext;

            // Overloaded constructor takes the arguments days, hours, minutes, seconds, miniseconds. 
            // Create a TimeSpan with miliseconds equal to the slider value.
            TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
            DataContextTmp.mediaView.Position = ts;
        }*/
    }
}
